package com.xinhua.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="t_courses")
public class Courses {
	private Integer id;
	private String name;
	
	private List<Teacher> teacher;
	private List<Major> major;
	
    public Courses() {
		// TODO Auto-generated constructor stub
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
    
	@ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinTable(name="course_major",
	           joinColumns={@JoinColumn(name="course_id",referencedColumnName="id")},
	           inverseJoinColumns={@JoinColumn(name="major_id",referencedColumnName="id")})
	@JsonIgnore
	public List<Major> getMajor() {
		return major;
	}

	public void setMajor(List<Major> major) {
		this.major = major;
	}

	@ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinTable(name="teacher_course",joinColumns={@JoinColumn(name="course_id",referencedColumnName="id")},
	           inverseJoinColumns={@JoinColumn(name="teacher_id",referencedColumnName="id")})
	@JsonIgnore
	public List<Teacher> getTeacher() {
		return teacher;
	}

	public void setTeacher(List<Teacher> teacher) {
		this.teacher = teacher;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

}
